<template>
  <div class="listr_in_index">
    <div class="titles">
      <h3>歌曲列表</h3>
      <span class="sub">{{ length }}首歌</span>
      <div class="more">
        播放：<span class="fc">{{ playCount }} </span>次
      </div>
    </div>
    <div class="song">
      <div class="header">
        <li class="w1"></li>
        <li class="w2">标题</li>
        <li class="w3">时长</li>
        <li class="w4">歌手</li>
      </div>
      <div class="mainer">
        <ul v-for="(item, index) in biaosheng" :key="index" class="lists">
          <li class="m1">
            <span>{{ index + 1 }}</span>
            <i></i>
          </li>
          <li class="m2">
            <img :src="item.al.picUrl" v-show="index < 3" />
            <i class="play"></i>
            <span class="handle" @click="playmusic(index)">{{ item.name }}</span>
            <i class="mv"></i>
          </li>
          <li class="m3">
            <span class="time">{{ min(item) }}:{{ sec(item) }}</span>
            <div class="show">
              <a text="添加到播放列表" class="a1"></a>
              <a text="收藏" class="a2"></a>
              <a text="分享" class="a3"></a>
              <a text="下载" class="a4"></a>
            </div>
          </li>
          <li class="m4">
            <router-link to="">{{ item.ar[0].name }}</router-link>
          </li>
        </ul>
      </div>
    </div>
    <Music :ids="ids" />
  </div>
</template>

<script>
import { reqPlayList } from "@/request/api";
import Music from "@/components/List/Music.vue";
export default {
  data() {
    return {
      length: 0,
      playCount: 0,
      biaosheng: [],
      ids: 1853404806,
    };
  },
  components: {
    Music,
  },
  props: ["playList"],
  computed: {
    id() {
      if (this.$route.query.id == undefined) return "19723756";
      console.log(this.$route.query.id);
      return this.$route.query.id;
    },
  },
  created() {
    reqPlayList("19723756").then((res) => {
      console.log(res.data.playlist);
      this.biaosheng = res.data.playlist.tracks;
      this.length = res.data.playlist.trackCount;
      this.playCount = res.data.playlist.playCount;
    });
  },
  methods: {
    min(song) {
      if (parseInt(song.dt / 60000) < 10)
        return "0" + parseInt(song.dt / 60000);
      else return parseInt(song.dt / 60000);
    },
    sec(song) {
      let x = parseInt(song.dt / 60000);
      let y = parseInt(song.dt / 1000 - x * 60);
      if (y < 10) return "0" + y;
      else return y;
    },
    playmusic(index) {
      this.ids = this.biaosheng[index].id;
      // console.log(this.ids);
    },
  },
};
</script>
 
<style lang = "less" scoped>
.listr_in_index {
  width: 670px;
  min-height: 400px;
  margin: 0 auto;
  .titles {
    width: 100%;
    height: 35px;
    border-bottom: 2px solid #c20c0c;

    h3 {
      font-family: "Microsoft Yahei", Arial, Helvetica, sans-serif;
      font-size: 20px;
      line-height: 28px;
      font-weight: normal;
      color: #333;
      float: left;
    }
    .sub {
      margin: 9px 0 0 20px;
      float: left;
      color: #666;
      font-size: 12px;
      font-family: Arial, Helvetica, sans-serif;
      -webkit-text-size-adjust: none;
    }
    .more {
      margin-top: 5px;
      height: 16px;
      float: right;
      font-size: 12px;
      .fc {
        color: #c20c0c;
        font-weight: bold;
      }
    }
  }
  .song {
    width: 100%;
    border: 1px solid #d9d9d9;
    .header {
      width: 100%;
      height: 39px;
      display: flex;
      li {
        border-right: 1px solid #d9d9d9;
        background-image: linear-gradient(
          rgb(255, 255, 255),
          rgb(240, 240, 240)
        );
        padding: 8px 10px;
        box-shadow: 0 1px 1px 1px rgba(0, 0, 0, 0.1);
      }
      .w1 {
        width: 77px;
      }
      .w2 {
        width: 326px;
      }
      .w3 {
        width: 91px;
      }
      .w4 {
        width: 174px;
      }
    }
    .mainer {
      width: 100%;
      display: block;
      font-size: 12px;
      a {
        color: #000;
        text-decoration: none;
      }
      ul:nth-of-type(even) {
        background: #e5e5e5;
      }
      ul:nth-of-type(odd) {
        background: #f6f6f6;
      }
      .good {
        height: 66px;
        span,
        a,
        i {
          display: block;
          margin-top: 20px !important;
          font-size: 12px;
        }
      }
      ul {
        height: 30px;
        width: 100%;
        display: flex;
        &:nth-child(-n + 3) {
          height: 80px;
          align-items: center;
        }
        &:hover .time {
          display: none !important;
        }
        &:hover .show {
          display: block !important;
        }

        li {
          padding: 6px 10px;
        }
        .m1 {
          width: 77px;
        
          padding: 6px 10px;
          line-height: 18px;
          span {
            float: left;
            width: 25px;
            height: 18px;
            color: #999;
            text-align: center;
          }
          i {
            margin: 0 8px;
            float: left;
            width: 16px;
            height: 17px;
            background: url("./images/icon.png") no-repeat -67px -283px;
          }
        }
        .m2 {
          width: 326px;
          display: flex;
          align-items: center;
          img {
            float: left;
            margin-right: 10px;
            width: 50px;
            margin-top: 3px;
          }
          .play {
            float: left;
            display: block;
            width: 17px;
            height: 17px;
            margin-right: 8px;
            background: url("./images/table.png") no-repeat -0px -103px;

            &:hover {
              background-position: -0px -128px;
              cursor: pointer;
            }
          }
          a {
            width: 200px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            float: left;
            &:hover {
              color: #666;
              cursor: pointer;
              text-decoration: underline;
            }
          }
        }
        .m3 {
          width: 91px;
          .time {
            display: block;
          }
          .show {
            width: 79px;
            height: 18px;
            display: none;
            a {
              margin: 2px 0 0 4px;
              width: 18px;
              height: 16px;
              display: block;
              float: left;
              background: url("./images/table.png") no-repeat;
              &:hover {
                cursor: pointer;
              }
            }
            .a1 {
              width: 13px;
              height: 13px;
              margin-top: 2px;
              margin-left: 0;
              background: url("./images/icon.png") no-repeat;
              background-position: 0 -700px;

              &:hover {
                background-position: -22px -700px;
              }
            }
            .a2 {
              background-position: 0 -174px;
              &:hover {
                background-position: -20px -174px;
              }
            }
            .a3 {
              background-position: 0 -195px;
              &:hover {
                background-position: -20px -195px;
              }
            }
            .a4 {
              background-position: -81px -174px;
              &:hover {
                background-position: -104px -174px;
              }
            }
          }
        }
        .m4 {
          width: 173px;
          color: #333;
          & a:hover {
            color: #666;
            cursor: pointer;
            text-decoration: underline;
          }
        }
      }
    }
  }
}
.handle{
  cursor: pointer;
}
</style>